<?php
namespace app\controller;

use think\Request;
use app\controller\Base;
use app\common\UtilService;
use app\model\EaWxSite;

class Site extends Base
{
    /**
     * [index 首页]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function index(Request $request)
    {
    	$param = UtilService::getMore([
    		['page', 1],
    		['pageSize', 10],
            ['type', ''], // 对应字段：type2
    		['son', ''],    // 对应字段：type3
    	]);

    	$arrs = [];

        # 网站二级分类
        $arrs['pla_type']  = EaWxSite::siteGroupName();

        # 最新加入站点
        $arrs['new_site'] = EaWxSite::field('id, title, pics, descs')->where('status', 1)->order('dates DESC, id DESC')->limit(10)->cache(600)->select()->toArray();

        # 三级分类
        $arrs['pla_type3'] = [];

        $arrs['list'] = EaWxSite::getPlatformList($param);

        if (isset($param['type']) && $param['type'] !== '') {

            $arrs['pla_type3'] = EaWxSite::where('status', 1)
                ->field('type3 as type')
                ->where('type2', $param['type'])
                ->group('type3')
                ->select()->toArray();
        }

        // dump($arrs);exit;

        return view('index', compact('arrs', 'param'));
    }

    /**
     * [info 详细]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function info(Request $request)
    {
    	$param = UtilService::getMore([
            ['id', ''],
    		['title', ''],
    	]);

        $info = EaWxSite::where('id', $param['id'])->find();
        $info->views = $info['views'] + 1;
        $info->save();

    	# 网站分类
        $arrs['pla_type'] = EaWxSite::siteGroupName();

        # 最新加入站点
        $arrs['new_site'] = EaWxSite::field('id, title, pics, descs')->where('status', 1)->order('dates DESC, id DESC')->limit(15)->cache(600)->select()->toArray();

        $arrs['pla_type3'] = EaWxSite::where('status', 1)
                ->field('type3 as type')
                ->where('type2', $info['type2'])
                ->group('type3')
                ->select()->toArray();

        # 下一个 5
        $xia = EaWxSite::field('id, title')->where('id', '>', $param['id'])->order('id ASC')->limit(1)->cache(120)->find();

        # 上一个 5
        $shang = EaWxSite::field('id, title')->where('id', '<', $param['id'])->order('id DESC')->limit(1)->cache(120)->find();

        return view('info', compact('info', 'arrs', 'xia', 'shang'));
    }
}
